home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.8 KB | 354 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLinShp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef SLGRGLOB_H
- #include "SLGrGlob.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWINK_H
- #include "FWInk.h"
- #endif
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef SLRENDER_H
- #include "SLRender.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRANSFORM_
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_LineShape
- #endif
-
- //========================================================================================
- // class FW_CLineShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CLineShape)
- FW_DEFINE_CLASS_M1(FW_CLineShape, FW_CShape)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(const FW_CLineShape& other) :
- FW_CShape(other),
- fStart(other.fStart),
- fEnd(other.fEnd)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape() :
- FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont)
- // fStart and fEnd are initialzied to 0's by default constructors
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(FW_Fixed xStart, FW_Fixed yStart,
- FW_Fixed xEnd, FW_Fixed yEnd,
- const FW_CInk& ink,
- const FW_CStyle& style) :
- FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
- fStart(xStart, yStart),
- fEnd(xEnd, yEnd)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(const FW_CPoint& start,
- const FW_CPoint& end,
- const FW_CInk& ink,
- const FW_CStyle& style) :
- FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
- fStart(start),
- fEnd(end)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::FW_CLineShape(FW_CReadableStream& stream) :
- FW_CShape(stream)
- {
- stream >> fStart;
- stream >> fEnd;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::~FW_CLineShape
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape::~FW_CLineShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CLineShape& FW_CLineShape::operator=(const FW_CLineShape& other)
- {
- if (this != &other)
- {
- FW_CShape::operator=(other);
-
- fStart = other.fStart;
- fEnd = other.fEnd;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Render(FW_CGraphicContext& gc) const
- {
- FW_PrivRenderLine(gc.GetEnvironment(),
- gc,
- fStart, fEnd,
- GetRenderVerb(),
- fInk,
- fStyle);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::RenderLine
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::RenderLine(FW_CGraphicContext& gc,
- const FW_CPoint& start,
- const FW_CPoint& end,
- const FW_CInk& ink,
- const FW_CStyle& style)
- {
- FW_PrivRenderLine(gc.GetEnvironment(),
- gc,
- start, end,
- FW_kFrame,
- ink,
- style);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_UNUSED(gc);
-
- rect.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
- rect.Sort();
- FW_Fixed halfPen = FW_Half(GetPenSize());
- rect.Inset(-halfPen, -halfPen);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::GetAnchorPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CLineShape::GetAnchorPoint() const
- {
- FW_CRect rect(fStart.x, fStart.y, fEnd.x, fEnd.y);
- rect.Sort();
- FW_Fixed halfPen = FW_Half(GetPenSize());
- rect.Inset(-halfPen, -halfPen);
-
- return rect.TopLeft();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Transform(Environment *ev, ODTransform* transform)
- {
- fStart.Transform(ev, transform);
- fEnd.Transform(ev, transform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::InverseTransform(Environment *ev, ODTransform* transform)
- {
- fStart.InverseTransform(ev, transform);
- fEnd.InverseTransform(ev, transform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Inset(FW_Fixed x, FW_Fixed y)
- {
- if (fStart.x > fEnd.x)
- {
- fStart.x -= x;
- fEnd.x += x;
- }
- else if (fStart.x < fEnd.x)
- {
- fStart.x += x;
- fEnd.x -= x;
- } // if fStart.x == fEnd.x don't do anything
-
- if (fStart.y > fEnd.y)
- {
- fStart.y -= y;
- fEnd.y += y;
- }
- else if (fStart.y < fEnd.y)
- {
- fStart.y += y;
- fEnd.y -= y;
- } // if fStart.y == fEnd.y don't do anything
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- fStart.x += deltaX;
- fStart.y += deltaY;
- fEnd.x += deltaX;
- fEnd.y += deltaY;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
- {
- fEnd.x += x - fStart.x;
- fEnd.y += y - fStart.y;
- fStart.x = x;
- fStart.y = y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CLineShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- FW_UNUSED(gc);
- if(fRenderVerb == FW_kNoRendering)
- return FALSE;
-
- return ::FW_HitTestLine(fStart, fEnd, test, tolerance);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CLineShape::Copy() const
- {
- return FW_NEW(FW_CLineShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::GetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::GetGeometry(FW_CPoint& start, FW_CPoint& end) const
- {
- start = fStart;
- end = fEnd;
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::SetGeometry
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::SetGeometry(const FW_CPoint& start, const FW_CPoint& end)
- {
- fStart = start;
- fEnd = end;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CLineShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CLineShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CShape::Flatten(stream);
-
- stream << fStart;
- stream << fEnd;
- }
-
-